﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utility
{
    public static class Extension
    {

        public static string ToCustomString(this object obj)
        {
            return obj == null|| obj==DBNull.Value ? "" : obj.ToString();
        }
        public static int ToInt(this object obj)
        {
            int result = 0;
            int.TryParse(obj.ToCustomString(), out result);
            return result;
        }
        public static bool ToBool(this object obj)
        {
            return obj == null || obj==DBNull.Value ? false : Convert.ToBoolean(obj);
        }
        public static decimal ToDecimal(this object obj)
        {
            decimal result = 0;
            decimal.TryParse(obj.ToCustomString(), out result);
            return result;
        }

        public static DateTime ToDateTime(this object obj)
        {
            DateTime result;
            DateTime.TryParse(obj.ToCustomString(), out result);
            return result;
        }
    }
}
